el-table-column<template>
  <div>
    <el-row :gutter="50">
      <el-col :span="12">
        <el-form label-width="80px" ref="resultForm" :model="resultForm">
          <el-table
            v-loading="loading"
            :data="resultList"
            highlight-current-row
            ref="dragTable"
            row-key="id"
            :default-expand-all="expand"
          >
            <el-table-column type="expand">
              <template slot-scope="scope">
                <el-form-item label="解释" prop="explain">
                  <el-input v-model="scope.row.explain" type="textarea" />
                </el-form-item>
                <el-form-item label="建议" prop="suggest">
                  <el-input v-model="scope.row.suggest" type="textarea" />
                </el-form-item>
                <el-form-item label="原因" prop="reason">
                  <el-input v-model="scope.row.reason" type="textarea" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="结论" align="center" prop="result" />
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="handleUpdate(scope.row)"
                  >编辑</el-button
                >
                <el-button
                  type="text"
                  size="small"
                  @click="handleDelete(scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </el-col>
      <el-col :span="12">
        <el-row :gutter="50">
          <el-table
            v-loading="loading"
            :data="detailList"
            highlight-current-row
          >
            <el-table-column label="项目" align="center" prop="projectName" />
            <el-table-column label="明细" align="center" prop="detail" />
            <el-table-column
              label="结果"
              align="center"
              prop="result"
              show-overflow-tooltip
            />
            <el-table-column label="提示" align="center" prop="tooltip" />
            <el-table-column label="范围" align="center" prop="range" />
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="handleDeleteDetail(scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-row>
        <el-row :gutter="50" style="margin-top: 20px">
          <el-table
            v-loading="loading"
            :data="abnormalProList"
            highlight-current-row
          >
            <el-table-column label="项目" align="center" prop="projectName" />
            <el-table-column
              label="小结"
              align="center"
              prop="result"
              show-overflow-tooltip
            />
          </el-table>
        </el-row>
      </el-col>
    </el-row>
    <!-- 对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="结论" prop="result">
          <el-input
            v-model="form.result"
            placeholder="请输入检查项目"
            type="textarea"
            :rows="4"
            :autosize="{ minRows: 4, maxRows: 8 }"
            show-word-limit
            maxlength="200"
            clearable
          />
        </el-form-item>
        <el-form-item label="医学解释" prop="result">
          <el-input
            v-model="form.result"
            placeholder="请输入医学解释"
            type="textarea"
            :rows="4"
            :autosize="{ minRows: 4, maxRows: 8 }"
            show-word-limit
            maxlength="200"
            clearable
          />
        </el-form-item>
        <el-form-item label="常见原因" prop="result">
          <el-input
            v-model="form.result"
            placeholder="请输入检查项目"
            type="textarea"
            :rows="4"
            :autosize="{ minRows: 4, maxRows: 8 }"
            show-word-limit
            maxlength="200"
            clearable
          />
        </el-form-item>
        <el-form-item label="指导意见" prop="result">
          <el-input
            v-model="form.result"
            placeholder="请输入检查项目"
            type="textarea"
            :rows="4"
            :autosize="{ minRows: 4, maxRows: 8 }"
            show-word-limit
            maxlength="200"
            clearable
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Sortable from "sortablejs";

export default {
  name: "TableData",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [
        {
          num: 0,
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        skipCount: 0,
        maxResultCount: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        result: [{ required: true, message: "请输入结论", trigger: "blur" }],
      },
      // 检查项目
      projectList: [
        {
          label: "[未]体格检查",
          value: "1",
          result: "222",
          range: "12",
        },
        {
          label: "[未]体格检查",
          value: "2",
          result: "222",
          range: "12",
        },
        {
          label: "dsdsa",
          value: "3",
          result: "222",
          range: "12",
        },
      ],
      // 结论列表
      resultList: [
        {
          id: "1",
          result: "结论111",
          explain: "解释",
          suggest: "建议",
          reason: "原因",
        },
        {
          id: "2",
          result: "结论222",
          explain: "解释",
          suggest: "建议",
          reason: "原因",
        },
        {
          id: "3",
          result: "结论333",
          explain: "解释",
          suggest: "建议",
          reason: "原因",
        },
        {
          id: "4",
          result: "结论444",
          explain: "解释",
          suggest: "建议",
          reason: "原因",
        },
      ],
      // 明细列表
      detailList: [
        {
          projectName: "项目名称",
          detail: "111",
          result: "结果",
          tooltip: "提示",
          range: "范围",
        },
        {
          projectName: "项目名称",
          detail: "111",
          result: "结果",
          tooltip: "提示",
          range: "范围",
        },
      ],
      // 异常项目
      abnormalProList: [
        {
          projectName: "体格检查",
          result:
            "血压偏低：定期复查血压，心动过缓，肥胖血压偏低：定期复查血压，心动过缓，肥胖",
        },
        {
          projectName: "体格检查",
          result: "血压偏",
        },
      ],
      // 异常结果表单
      resultForm: {},
      // TODO: 拖拽
      sortable: null,
      // table  expand
      expand: false,
    };
  },
  created() {
    this.$nextTick(() => {
      this.setSort();
    });
  },
  computed: {},
  methods: {
    setSort() {
      const el = this.$refs.dragTable.$el.querySelectorAll(
        ".el-table__body-wrapper > table > tbody"
      )[0];
      this.sortable = Sortable.create(el, {
        ghostClass: "sortable-ghost", // Class name for the drop placeholder,
        setData: function (dataTransfer) {
          // to avoid Firefox bug
          // Detail see : https://github.com/RubaXa/Sortable/issues/1012
          dataTransfer.setData("Text", "");
        },
        onEnd: (evt) => {
          const targetRow = this.resultList.splice(evt.oldIndex, 1)[0];
          this.resultList.splice(evt.newIndex, 0, targetRow);
        },
      });
    },
    // 编辑按钮
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.title = row.result;
      // const id = row.id || this.ids
      // getProject(id).then((response) => {
      //   this.form = response.data
      //   this.open = true
      //   this.title = '编辑'
      // })
    },
    // 删除明细按钮
    handleDeleteDetail() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    // 删除按钮
    handleDelete() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // listProject(this.queryParams).then((response) => {
      //   this.projectList = response.rows
      //   this.total = response.total
      //   this.loading = false
      // })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.skipCount = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 提交按钮
    submitForm() {},
  },
};
</script>

<style scoped>
/* .collapse-title {
  flex: 1 0 90%;
  order: 1;
}

.el-collapse-item__header {
  flex: 1 0 auto;
  order: -1;
}
.el-collapse,
.el-collapse-item__wrap {
  border: none;
} */
</style>
<style>
.sortable-ghost {
  opacity: 0.8;
  color: #fff !important;
  background: #409eff !important;
}
</style>